<?


	// 0.0000000a FTA helper.. this will form the basis for the fast track automation..
	
	/**
	 fta will comprise of two or three key parts..
	
	1. Classes that perform the site specific behaviour and standard behavior of the elements
	
	2. high level helper functions that wrap up the underlying classes so that items can be pasted into the page
	
	3. a cache and loading mechanism.
	
	4. simple class overrides to determine what subclasses to use.
		
	*/
	
	if (!defined('PHP_VERSION_ID')) {
	    $version = explode('.', PHP_VERSION);
	    define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
	}

	// add the current fta directory to the include path.. 
	set_include_path(get_include_path() . ":" . dirname(__FILE__));
		
	/**
		this function registers and loads the listed fta modules for a given page
		
		it takes one argument which is a module list.
	*/

	function fta_registerModules($moduleList) {

		array_unshift($moduleList,"FTAObject");

		// at this point in time we simply 
		if (is_array($moduleList) && 0 < count($moduleList)){
			//wish i could use a closure here..
			array_map(
				//'nz\co\innovanet\fta\fta_include',
				'fta_include',
				$moduleList);
		
		}
	}
	
	
//	function fta_moduleListMapAndInclude($mod) {
//		static $includedFiles;
//		if (is_null($includedFiles)){
//			$includedFiles = array();
//		}
//
//		fta_include($mod);
//		
//		return $mod;
//	}
	

	function fta_include($mod){
		global $FTA_INCLUDED_FILES;
		if (is_null($FTA_INCLUDED_FILES)){
			$FTA_INCLUDED_FILES = array();
		}
		if (!in_array($mod,$FTA_INCLUDED_FILES)) {
			array_push($FTA_INCLUDED_FILES,$mod);
			
			//echo "$mod<br/>";
			 
			//require_once($mod . ".php");//note that variables declared .. will only have a scope here.. meh.. make sure we add things to global
			require_once($mod . ".php");
		}
		return $FTA_INCLUDED_FILES;
	}
	

	
	
	function fta_setPageScope($scope){
		global $fta_;
		$fta_->setPageScope($scope);
	}
	
	
	function fta_pageCacheIdentIfierFromUri(){
		$uri = $_SERVER['REQUEST_URI'];
		return fta_pageCacheIdentifierFromString($uri);
	}
	
	function fta_pageCacheIdentifierFromString($string){
		
		if (strrpos($string,'/') == strlen($string) -1)
			$string = substr($string,0,strlen($string) -1 );

		if (strpos($string,'/') == 0)
			$string = substr($string,1);
			
		return strtolower(preg_replace('/[[:punct:]]/','_',$string));		
	}
		
	//this is a super global .. that all static things are stuck into.. as i dont really like how php handles static..
	// and pointers and what not..
	fta_registerModules(array("FTAObject","FTAGlobal","FTAException/FTAException"));
	global $fta_;
	$fta_ = new FTAGlobal();
	$fta_->startSession(false);
